package com.example.book.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.book.dao.ShopCarDao;
import com.example.book.entity.ShopCar;
import com.example.book.entity.vo.ShopCarVo;
import com.example.book.service.ShopCarService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * (ShopCar)表服务实现类
 *
 * @author makejava
 * @since 2022-12-12 16:10:04
 */
@Service("shopCarService")
public class ShopCarServiceImpl extends ServiceImpl<ShopCarDao, ShopCar> implements ShopCarService {
    @Autowired
    ShopCarDao shopCarDao;

    //多表查询 根据条件自己灵活调换
    @Override
    public List<ShopCarVo> getAllShopCarVo(ShopCar shopCar) {
        Page page = new Page(1,10);
        QueryWrapper<ShopCar> qw = new QueryWrapper<>();
        if(shopCar.getUserId()!=null){
            qw.eq("s.user_id",shopCar.getUserId());
        }
        if(shopCar.getBookId()!=null){
            qw.eq("s.book_id",shopCar.getBookId());
        }
        qw.orderByDesc("s.create_time");
        return shopCarDao.getAllShopCarVo(qw,page);
    }
}

